package com.logic.modular.act.cultivate;

import com.comment.util.JwtUtils;
import com.comment.util.message.ResponseResult;
import com.logic.modular.act.cultivate.vo.SignInActionVo;
import com.logic.modular.act.playerInfo.vo.PlayerInfoVo;
import com.logic.modular.game.statistical.service.impl.PlayerStatisticalPool2ServiceImpl;
import com.logic.modular.game.signIn.domain.PlayerSignInAward;
import com.logic.modular.game.signIn.service.impl.PlayerSignInAwardServiceImpl;
import com.logic.modular.game.signIn.service.impl.PlayerSignInServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 签到
 */
@Slf4j
@Api(tags = "签到")
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("/signInAct")
public class SignInAction {
    @Resource
    private PlayerSignInAwardServiceImpl playerSignInAwardService;
    @Resource
    private PlayerSignInServiceImpl userSignInService;
    @Resource
    private PlayerStatisticalPool2ServiceImpl playerStatisticalPool2ServiceImpl;

    @ApiOperation(value = "签到")
    @PostMapping("/sign-in")
    public ResponseResult<?> signIn(@RequestHeader String token) {
        return ResponseResult.success("签到成功", userSignInService.signIn(com.logic.comment.util.JwtUtils.getPlayerId(token)));
    }

    @ApiOperation(value = "补签到")
    @PostMapping("/supplementarySignIn")
    public ResponseResult<?> supplementarySignIn(
            @RequestHeader String token,
            @Valid @RequestBody PlayerInfoVo.PlayerVo.supplementarySignIn param
    ) {
        return ResponseResult.success("补签成功", userSignInService.supplementarySignIn(
                com.logic.comment.util.JwtUtils.getPlayerId(token), param.getDayOfMonth()
        ));
    }


    @ApiOperation(value = "签到信息")
    @PostMapping("/getUserSignInOfYear")
    public ResponseResult<?> getUserSignInOfYear(
            @RequestHeader String token,
            @Valid @RequestBody PlayerInfoVo.PlayerVo.getUserSignInOfYear param
    ) {
        return ResponseResult.success("签到成功", userSignInService.getUserSignInOfYear(com.logic.comment.util.JwtUtils.getPlayerId(token), param.getYear()));
    }


    @ApiOperation(value = "累计签到数")
    @PostMapping("/accumulatedAttendance")
    public ResponseResult<Long> accumulatedAttendance(@RequestHeader String token) {
        return ResponseResult.success(playerStatisticalPool2ServiceImpl.select(JwtUtils.getPlayerId(token), 60).getValue());
    }

    @ApiOperation(value = "7日签到列表")
    @PostMapping("/7th/list")
    public ResponseResult<List<PlayerSignInAward>> signInOnThe7thList(@RequestHeader String token) {
        return ResponseResult.success(playerSignInAwardService.list(JwtUtils.getPlayerId(token), 7));
    }

    @ApiOperation(value = "7日签到领取奖励")
    @PostMapping("/7th/claimRewards")
    public ResponseResult<?> signIn7thClaimRewards(
            @RequestHeader String token, @Valid @RequestBody SignInActionVo.signIn7thClaimRewards pram
    ) {
        return ResponseResult.success(playerSignInAwardService.signIn7thClaimRewards(JwtUtils.getPlayerId(token), pram.getId()));
    }

    @ApiOperation(value = "30日签到列表")
    @PostMapping("/30th/list")
    public ResponseResult<List<PlayerSignInAward>> signInOnThe30thList(@RequestHeader String token) {
        return ResponseResult.success(playerSignInAwardService.list(JwtUtils.getPlayerId(token), 30));
    }

    @ApiOperation(value = "30日签到领取奖励")
    @PostMapping("/30th/claimRewards")
    public ResponseResult<?> signIn30thClaimRewards(
            @RequestHeader String token, @Valid @RequestBody SignInActionVo.signIn30thClaimRewards pram
    ) {
        return ResponseResult.success(playerSignInAwardService.signIn30thClaimRewards(JwtUtils.getPlayerId(token), pram.getId()));
    }
}
